#ifndef __GLF_CRCCHECKER_H_INCLUDED__
#define __GLF_CRCCHECKER_H_INCLUDED__

#include <glf/core/types.h>
#include <string>
#include <map>

namespace glf {

class CrcChecker {

public:
	static void AddCrcMap(const char *filename, bool dynamic);
	static uint CRC32(const void *buffer, int size, uint currentCRC = 0);
	static bool HasFileEntry(const char *filename);
	static bool DoCrcCheck(const char *filename, const void *buffer, int size);
	static void SetFileEntry(const char *filename, uint crc, bool dynamic);
	static void AddFileEntry(const char *filename, uint crc, bool dynamic);
	static void UpdateFileEntry(const char *filename, const void *buffer, int size);
	static void SetDynamicMapFileName(const char *filename);

private:
	static void _WriteDynamicCrcMap();
	static void _CypherBuffer(const char *buffer, char *(&cypheredBuffer), int size);
	static void _DecypherBuffer(const char *cypheredBuffer, char *(&buffer), int size);

	// <crc, isDynamic>
	typedef std::pair<glf::uint, bool> DataType;
	// <filename, <crc, isDynamic>>
	typedef std::map<std::string, DataType> CrcMap;

	static CrcMap mCrcMap;
	static std::string mDynMapFileName;
};

} //namespace glf

#endif
